=begin
require File.dirname(__FILE__)+'/../lib/elements/element_Opportunity.rb'
require File.dirname(__FILE__)+'/../lib/reporting.rb'
require File.dirname(__FILE__)+'/../lib/std_lib.rb'
require 'watir'
require 'watir/ie'
require 'watir/contrib/enabled_popup'
require 'watir/testcase'

#CRM_STD_LIB.login($product,$username,$password)
class Create_Opportunity < Watir::TestCase
    $ie = Watir::IE.attach(:title,"Home")
    $ie.bring_to_front
    $ie.link(:text,"Opportunities").click
    def test_setup
        filename  = File.basename(__FILE__).gsub(/\.rb/, "")
        begin
            $log=Reporting.new(File.dirname(__FILE__)+'/../doc/report/'"",filename)
            @@oppname = "Tonytest_"+Time.now.strftime("%Y%m%d")+"_opportunity"
        rescue
            puts $!
            puts $@
            $log.close unless $log.nil?
        end
    end
    # Add new deal to an Org
    def test_add_new_opportunity
        $log.test_notes("CreateNewOpportunityTest")
        $log.test_notes("Start to Test Create New Opportunity")
        Element::CreateOpportunity.new_opportunity_button(2).click
        sleep 1
#=begin
        def count_contact
            @array = []
            if $ie.checkbox(:name=>"ci").exist?
                for i in 0..100
                    if $ie.checkbox(:name=>"ci",:index=>i+1).exist?
                        i+=1
                        @array << i
                    else
                        break
                    end
                    return @array[rand(i)]
                end
            else
                return 0
            end

        end
        @@contactnum = count_contact
#=end
        Element::CreateOpportunity.opportunity_name_text_field.set(@@oppname)
        Element::CreateOpportunity.opportunity_account_text_field.set("Tonytest_Account")
        Element::CreateOpportunity.sales_stage_select_list.select("E&I 15%")
        Element::CreateOpportunity.market_select_list.select("Campgrounds")
        Element::CreateOpportunity.submarket_select_list.select("Marinas")
        Element::CreateOpportunity.primary_org_type_select_list.select("Marinas")

        Element::CreateOpportunity.save_button(1).click

        sleep 5
        #$log.test_validate(Element::CreateDeal.deal_name_text_field.value.include?(@@dealname),"Deal Name correct or not")
        #$log.test_validate(Element::CreateDeal.deal_product_family_select_list.text.include?("ACC"),"Product Family Name correct or not")
        #$log.test_validate(Element::CreateDeal.deal_primary_status_select_list.text.include?("Closed (100%)"),"Primary Status correct or not")
        #$log.test_validate(Element::CreateDeal.deal_close_date_text_field.value.include?($date),"Close Date correct or not")
        $log.test_validate($ie.text.include?(@@oppname),"Opportunity name correct or not")
        $log.test_validate($ie.text.include?("Tonytest_Account"),"Account name correct or not")
        $log.test_validate($ie.text.include?("E&I 15%"),"Sales Stage correct or not")
        $log.test_validate($ie.text.include?("Campgrounds"),"Market name correct or not")
        $log.test_validate($ie.text.include?("Marinas"),"Submarket name correct or not")
        $log.test_validate($ie.text.include?("Marinas"),"Primary Ory Type correct or not")
    end
    
    def test_reset

    end

    def test_tear_down
        @@for = nil
        @@search_in = nil
    end


    class NewOrg < Watir::TestCase
        def test_setup
        end

        def test_tear_down
            $log.close unless $log.nil?
        end
    end

end
=end


